define(function (require,exports,module){
	/**--tmpl-require--**/

	require('area');
	require('areaselect');

	require('jtemplate');
	require('jdialog');
	common = require('common');

	exports.init = function(){
		/**--tmpl-todo--**/

		/**-- deleteopt --**/
		$(".js-delete").click(function(){
			var id = $(this).attr('data-id');
			layer.confirm('确定要删除吗',['确定','取消'],function(){
				layer.load();
				$.post(exports.deleteUrl,{id:id},function(data){
					layer.closeAll('loading');
					if(data.code == 0 || data.code=='success'){
						layer.msg('删除成功');
						document.location.reload();
					}else{
						layer.msg(data.message);
					}
				},'json');
			});
		});
		

		$(".js-edit").click(function(){
			id = $(this).attr('data-id');
			/**--tmpl-editlayer--**/
			$.get(exports.detailUrl,{id:id},function(data){
		
				var options = {
					type : 1,
					area : ['800px','500px'],
					content : JTemplate.render("editpanel",data),
					btn : {
						'确定' :function(){
							var form = $("#editpanel-form");
							form.validate({
								rules: {

										   /**--tmpl-editrules--**/

									   },
								messages : {  
											   /**--tmpl-editmessages--**/
										   },  

								submitHandler : function(form){

									$(form).find('input[name=id]').remove();
									$(form).append("<input type='hidden' name='id' value='"+id+"' >");
									var data = $(form).serialize();
									common.ajaxResult(exports.editUrl,data);

								}
							});
							form.submit();
						},
						"取消" : function(){
						
						}
					}
				};
				var options = $.extend(__global.jdialog, options);
				var popWin = JDialog.win.work(options);

				/**--tmpl-edittodo--**/

				/**-- editselected --**/
				$("select[name='data[userid]'] option").each(function(){
					if(data.userid == $(this).val()){
						$(this).prop('selected',true);
					}
				});
				
				/**-- baidumap --**/
					 var map = new BMap.Map("position-position");
					 map.centerAndZoom(new BMap.Point(116.328749,40.026922), 13);
					 map.enableScrollWheelZoom(true);
					 var geoc = new BMap.Geocoder();
					 map.addEventListener("click", function(e){        
						 var pt = e.point;
						 geoc.getLocation(pt, function(rs){
							 var addComp = rs.addressComponents;
							 map.clearOverlays();
							 map.centerAndZoom(rs.point, 13);
							 var marker = new BMap.Marker(rs.point);  // 创建标注
							 map.addOverlay(marker);               // 将标注添加到地图中
							 var txt = addComp.province  + addComp.city  + addComp.district  + addComp.street + addComp.streetNumber;
							 var label = new BMap.Label(txt,{offset:new BMap.Size(20,-10)});
							 marker.setLabel(label);
							 marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
							 $("input[name='data[position]']").remove();
							 $("input[name='data[positiontext]']").remove();
							 $("#position-position").after("<input type='hidden' name='data[position]' value='"+rs.point.lat + "," + rs.point.lng+"'>");
							 $("#position-position").after("<input type='hidden' name='data[positiontext]' value='"+ txt +"'>");
						 });        
					 });
					if(typeof(data) != "undefined" && data && data.position){
						pt = data.position.split(',');
						map.centerAndZoom(new BMap.Point(pt[1],pt[0]), 13);
						var marker = new BMap.Marker(new BMap.Point(pt[1],pt[0]));  // 创建标注
						map.addOverlay(marker);               // 将标注添加到地图中
						marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
				
					}
				
				/**-- editselected --**/
				$("select[name='data[sex]'] option").each(function(){
					if(data.sex == $(this).val()){
						$(this).prop('selected',true);
					}
				});
				
				/**-- editselected --**/
				$("select[name='data[three_in_one]'] option").each(function(){
					if(data.three_in_one == $(this).val()){
						$(this).prop('selected',true);
					}
				});
				

				
			},'json');
			
		});
		/**--tmpl-othertodo--**/
	};

	/**--tmpl-otherfunction--**/
});
